package fr.epsi.activities.employe;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.os.Debug;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;
import com.example.MyLittleHotel.R;
import fr.epsi.BDD.BDD;


import java.sql.SQLException;

/**
 * Created by Florent Baudon on 21/05/2014.
 */
public class FicheEmployeActivity extends Activity implements View.OnClickListener{

    private TextView nom, prenom, service, contrat, temps;
    private BDD bdd;
    private Cursor cListInfos;

    //Ajout et config du bouton



    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ficheemployelayout);

        prenom = (TextView)findViewById(R.id.fichePrenom);
        nom = (TextView)findViewById(R.id.ficheNom);
        service = (TextView)findViewById(R.id.ficheService);
        contrat = (TextView)findViewById(R.id.ficheContrat);
        temps = (TextView)findViewById(R.id.ficheTemps);
        ImageButton delete = (ImageButton)findViewById(R.id.deleteButton);

        delete.setOnClickListener(this);

                Bundle b = this.getIntent().getExtras();
       prenom.setText(b.getString("prenom"));
       nom.setText(b.getString("nom"));

        try {
            bdd = new BDD();
            bdd.open(this);
            cListInfos = bdd.getEmployeFiche(b.getString("nom"), b.getString("prenom"));
        }catch (SQLException e){
            e.printStackTrace();
        }
        if(cListInfos!=null && cListInfos.moveToFirst()) {
            service.setText(cListInfos.getString(4));
            contrat.setText(cListInfos.getString(3));
            temps.setText(cListInfos.getString(5));
        }
    }

    public void onClick(View view) {
            try {
                bdd.open(this);
                bdd.deleteEmploye(nom.getText().toString(), prenom.getText().toString());
                Toast t = Toast.makeText(this, nom.getText().toString() + " " + prenom.getText().toString() + "suppprimé", Toast.LENGTH_SHORT);
                t.show();
                finish();

            } catch (SQLException e) {
                e.printStackTrace();
            }

}
}